All files / src/app/recipes/[id] utils.ts

0% Statements 0/18
0% Branches 0/6
0% Functions 0/5
0% Lines 0/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26                                                   
export const extractYoutubeId = (url: string): string | null => {
  try {
    const parsed = new URL(url);
    if (parsed.hostname.includes('youtu.be')) {
      return parsed.pathname.slice(1);
    }
    return parsed.searchParams.get('v');
  } catch {
    return null;
  }
};
 
export const getDifficultyColor = (key: string) => {
  if (key === 'medium') return 'yellow';
  if (key === 'hard') return 'red';
  return 'green';
};
 
export const scaleQuantity = (quantity: number, multiplier: number): number => {
  return +(quantity * multiplier).toFixed(2);
};
 
export const sortByOrder = <T extends { order: number }>(items: T[]): T[] => {
  return [...items].sort((a, b) => a.order - b.order);
};